package com.hyacinth.future;

import com.sun.org.apache.regexp.internal.RE;

/**
 * 虚实现
 * @author zhangfb
 * @version 1.0.0.1
 * @since JDK 1.8
 */
public class FutureDate implements Data {

    private RealData realData;
    private boolean isReady = false;

    public synchronized void setResult(RealData realData) {
        if (isReady) {
            return;
        }
        this.realData = realData;
        isReady = true;
        /**
         * 通知 {@link #getResult}
         */
        notifyAll();
    }


    @Override
    public synchronized String getResult() {
        while (!isReady) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return realData.getResult();
    }
}
